package thread;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;

import javax.swing.JOptionPane;

import util.DBUtil;

public class SignChildThread extends Thread{
	private BufferedWriter writer;
	private BufferedReader reader;
	
	public SignChildThread(BufferedWriter writer, BufferedReader reader) {
		super();
		this.writer = writer;
		this.reader = reader;
	}

	@Override
	public void run() {
		try {
			String signString = reader.readLine();
			String buf[] = signString.split("\\\\");
			String loginName = buf[0];
			String password = buf[1];
			
			if(!DBUtil.checkUser(loginName)){
				if(DBUtil.sign(loginName, password)){
					//注册成功，返回消息通知客户端
					writer.write("200\n");
					writer.flush();
				}
				else{
					System.out.println("in sign thread");
					writer.write("404\n");
					writer.flush();
				}
			}
			else{
				writer.write("000\n");
				writer.flush();
			}
			
			reader.close();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
